<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      img {
        width: 600px;
      }
    </style>
  </head>
  <body>
    <img src="./images/1.png" alt="我是播仔" />
  </body>
</html>
<script>
  // 当页面刷新的时候页面的图片页随机换
  const arr = [
    "./images/1.png",
    "./images/2.png",
    "./images/3.png",
    "./images/4.png",
  ];

  // 1.生成随机数
  // const random = Math.random()*arr.length;
  const random = parseInt(Math.random() * arr.length);
  // 2.获取图片信息赋值给img.src
  const img = document.querySelector("img");  //获取图片信息
  img.src = arr[random];  //设置给img路径src
</script>
